/*
 *  10653.cxx
 *
 *      Author : Pallab
 *      Created on: 1:50:06 AM - 2012:12:18
 *      "I have not failed, I have just found 10000 ways that won't work."
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait ( double seconds ) {
    double endtime = clock() + ( seconds * CLOCKS_PER_SEC );
    while ( clock() < endtime ) {
        ;
    }
}
template<class T>
    inline T fastIn() {
    register char c=0;
    register T a=0;
    bool neg=false;
    while ( c<33 ) c=getchar();
    while ( c>33 ) {
        if ( c=='-' ) {
            neg=true;
        } else {
            a= ( a*10 ) + ( c-'0' );
        }
        c=getchar();
    }
    return neg?-a:a;
}
const int MXN=1000+5;
bool grid[MXN][MXN];

int R,C;
int sR,sC,dR,dC;
inline void read() {
    SET ( grid,true ); //initially all grid are true = no bombs

    int row_count=fastIn<int>();
    for ( int i=0; i<row_count; ++i ) {
        int row_number=fastIn<int>();
        int bomb_count=fastIn<int>();

        for ( int j=0; j<bomb_count; ++j ) {
            int col_number=fastIn<int>();
            grid[row_number][col_number]=false;
        }
    }

    sR=fastIn<int>(),sC=fastIn<int>();
    dR=fastIn<int>(),dC=fastIn<int>();
}
struct node {
    int r,c;
    node ( int r_,int c_ ) {
        r=r_,c=c_;
    }
};

const int rr[]= {-1,+1,+0,+0 };
const int cc[]= {+0,+0,-1,+1 };
int dist[MXN][MXN];
bool taken[MXN][MXN];
inline int bfs ( int sr, int sc, int dr, int dc ) {
    //1: initialize
    memset ( dist,0,sizeof ( dist ) );
    memset ( taken,false,sizeof ( taken ) );

    //2: start run
    queue< node > q;
    q.push ( node ( sr,sc ) );
    dist[sr][sc]=0;
    taken[sr][sc]=true;

    while ( q.empty() ==false ) {
        int cur_r=q.front().r;
        int cur_c=q.front().c;
        q.pop();

        for ( int i=0; i<4; ++i ) {
            int nxt_r = cur_r+rr[i];
            int nxt_c = cur_c+cc[i];
            if ( nxt_r>=0 && nxt_r<R && nxt_c>=0&&nxt_c<C ) {
                //if not already visited and there is no bomb in this (r,c) position
                if ( taken[nxt_r][nxt_c]==false && grid[nxt_r][nxt_c]==true ) {
                    dist[nxt_r][nxt_c]=dist[cur_r][cur_c]+1;

                    //3: if reached destination
                    if ( nxt_r==dr&&nxt_c==dc ) {
                        return dist[nxt_r][nxt_c];
                    }

                    taken[nxt_r][nxt_c]=true;
                    q.push ( node ( nxt_r,nxt_c ) );
                }
            }
        }
    }
    //4: if could never reach the destination 
    return -1; //kill
}
inline void proc() {
    //run bfs and get result
    int result=bfs ( sR,sC,dR,dC );
    cout<<result<<"\n";
}
int main() {
    int kase = 1;
#if defined( xerxes_pc )
    if ( !freopen ( "in1", "r", stdin ) )
        puts ( "error opening file in " ), assert ( 0 );
    kase = 1;
#endif

    while ( scanf ( "%d %d",&R,&C ) ==2 ) {
        if ( R==0&&C==0 ) break;
        read();
        proc();
    }
    return 0;
}
// kate: indent-mode cstyle; indent-width 4; replace-tabs on; 
